Socket
Socket
Sign inDemoInstall

hashlru

Package Overview
Dependencies
Maintainers
3
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hashlru

simpler faster substitute for LRU


Version published
Weekly downloads
161K
decreased by-3.05%
Maintainers
3
Weekly downloads
 
Created

What is hashlru?

The hashlru npm package is a simple and efficient Least Recently Used (LRU) cache implementation. It allows you to store a limited number of items and automatically evicts the least recently used items when the cache reaches its capacity.

What are hashlru's main functionalities?

Creating an LRU Cache

This feature allows you to create an LRU cache with a specified capacity. In this example, the cache can hold up to 3 items.

const LRU = require('hashlru');
const cache = LRU(3);

Setting and Getting Items

You can set items in the cache using the `set` method and retrieve them using the `get` method. If the item is in the cache, it will be returned; otherwise, `undefined` will be returned.

cache.set('key1', 'value1');
console.log(cache.get('key1')); // Outputs: 'value1'

Evicting Items

When the cache reaches its capacity, the least recently used item will be evicted to make room for new items. In this example, 'key1' is evicted when 'key4' is added.

cache.set('key1', 'value1');
cache.set('key2', 'value2');
cache.set('key3', 'value3');
cache.set('key4', 'value4');
console.log(cache.get('key1')); // Outputs: undefined

Checking Cache Size

You can check the current size of the cache using the `size` property.

console.log(cache.size); // Outputs: 3

Other packages similar to hashlru

FAQs

Package last updated on 22 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc